package algo.sort;

public class Down2UpMergeSort <T extends Comparable<? super T>> extends MergeSort<T>{
    @Override
    public void sort(T[] nums) {
        int len = nums.length;
        aux = (T[]) new Comparable[len];

        for (int sz = 1; sz < len; sz += sz) {
            for (int lo = 0; lo<len - sz; lo += sz + sz) {
                merge(nums, lo, lo + sz - 1, Math.min(lo + sz + sz - 1, len - 1));
            }
        }
    }

    @Override
    public void sortDesc(T[] nums) {
        int len = nums.length;
        aux = (T[]) new Comparable[len];

        for (int sz = 1; sz < len; sz += sz) {
            for (int lo = 0; lo<len - sz; lo += sz + sz) {
                mergeDesc(nums, lo, lo + sz - 1, Math.min(lo + sz + sz - 1, len - 1));
            }
        }
    }
}
